using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArtificialIntelligence;
using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;
using SymbolicComputation.AI;
namespace SymbolicComputation
{
    public class IsolateSingleVariable : SolveEquationBase
    {
        String variableBeingSolvedFor;

        public static String IsolateEquation(String transformMe, String inVariableBeingSolvedFor)
        {
            IsolateSingleVariable iso = new IsolateSingleVariable();
            return iso.Isolate(transformMe, inVariableBeingSolvedFor);
        }

        public String Isolate(String transformMe, String inVariableBeingSolvedFor)
        {
            variableBeingSolvedFor = inVariableBeingSolvedFor;
            return Isolate(Miscellaneous.EquationToSyntaxNode(transformMe),variableBeingSolvedFor).ToString();
        }

        public SyntaxNode Isolate(SyntaxNode transformMe, String inVariableBeingSolvedFor)
        {
            variableBeingSolvedFor = inVariableBeingSolvedFor;
            ai.trimmedJobStatePopulation = 100;
            ai.maxWhileLoops = 1000;
            return Solve(transformMe);
        }

        public override void AssessJob(Job passJob)
        {
            SyntaxNode equation = passJob.jobState;
            Double assessment = 0;
            assessment -= equation.ToString().Length;
            assessment -= Assessers.VariablesOnRight(equation.ToString(), variableBeingSolvedFor) * 100;
            assessment -= Assessers.RepeatedVariables(equation, variableBeingSolvedFor) * 50;
            String eq = equation.ToString();
            List<String> sides = Miscellaneous.Split(eq, "==");
            if (sides[1].Contains(variableBeingSolvedFor) == false)
            {
                assessment -= sides[0].Length * 1;
                assessment += 1000;
            }
            if (sides[0] == variableBeingSolvedFor)
            {
                assessment += 1000;
                passJob.approved = true;
            }
            passJob.assessment = assessment;
        }
    }
}